<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是C语言基础——变量与运算符相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV01-02-C语言-变量与运算符">
<meta property="og:url" content="https://sumumm.github.io/post/ce2c2639.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是C语言基础——变量与运算符相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV01-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/LV01-02-C%E8%AF%AD%E8%A8%80-%E5%8F%98%E9%87%8F%E4%B8%8E%E8%BF%90%E7%AE%97%E7%AC%A6/img/image-20220402162636518.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV01-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/LV01-02-C%E8%AF%AD%E8%A8%80-%E5%8F%98%E9%87%8F%E4%B8%8E%E8%BF%90%E7%AE%97%E7%AC%A6/img/image-20220402163051101.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV01-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/LV01-02-C%E8%AF%AD%E8%A8%80-%E5%8F%98%E9%87%8F%E4%B8%8E%E8%BF%90%E7%AE%97%E7%AC%A6/img/image-20220402165150484.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV01-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/LV01-02-C%E8%AF%AD%E8%A8%80-%E5%8F%98%E9%87%8F%E4%B8%8E%E8%BF%90%E7%AE%97%E7%AC%A6/img/image-20220731101731680.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV01-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/LV01-02-C%E8%AF%AD%E8%A8%80-%E5%8F%98%E9%87%8F%E4%B8%8E%E8%BF%90%E7%AE%97%E7%AC%A6/img/image-20220731101932124.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV01-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/LV01-02-C%E8%AF%AD%E8%A8%80-%E5%8F%98%E9%87%8F%E4%B8%8E%E8%BF%90%E7%AE%97%E7%AC%A6/img/image-20220731103108642-16827691783556.png">
<meta property="article:published_time" content="2022-01-11T08:29:55.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:56.983Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="LV01-C语言基础">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV01-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/LV01-02-C%E8%AF%AD%E8%A8%80-%E5%8F%98%E9%87%8F%E4%B8%8E%E8%BF%90%E7%AE%97%E7%AC%A6/img/image-20220402162636518.png">


<link rel="canonical" href="https://sumumm.github.io/post/ce2c2639.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/ce2c2639.html","path":"post/ce2c2639.html","title":"LV01-02-C语言-变量与运算符"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV01-02-C语言-变量与运算符 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E5%8F%98%E9%87%8F"><span class="nav-text">一、变量</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%8F%98%E9%87%8F%E7%9A%84%E5%AE%9A%E4%B9%89"><span class="nav-text">1. 变量的定义</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%8F%98%E9%87%8F%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="nav-text">2. 变量的使用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E5%8F%98%E9%87%8F%E7%9A%84%E5%BC%95%E7%94%A8"><span class="nav-text">2.1 变量的引用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E5%8F%98%E9%87%8F%E7%9A%84%E8%B5%8B%E5%80%BC"><span class="nav-text">2.2 变量的赋值</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%8F%98%E9%87%8F%E7%9A%84%E4%BD%9C%E7%94%A8%E5%9F%9F"><span class="nav-text">3. 变量的作用域</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E5%8F%98%E9%87%8F%E4%BD%9C%E7%94%A8%E5%9F%9F%E7%B1%BB%E5%88%AB"><span class="nav-text">3.1 变量作用域类别</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E4%BD%9C%E7%94%A8%E5%9F%9F%E7%9A%84%E9%87%8D%E5%8F%A0%E4%BC%9A%E5%8F%91%E7%94%9F%E4%BB%80%E4%B9%88%EF%BC%9F"><span class="nav-text">3.2 作用域的重叠会发生什么？</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-%E4%B8%8D%E5%90%8C%E5%AD%98%E5%82%A8%E7%B1%BB%E5%9E%8B%E5%8F%98%E9%87%8F%E7%9A%84%E4%BD%9C%E7%94%A8%E5%9F%9F"><span class="nav-text">3.3 不同存储类型变量的作用域</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E5%8F%98%E9%87%8F%E7%9A%84%E5%AD%98%E5%82%A8%E6%A8%A1%E5%9E%8B"><span class="nav-text">4. 变量的存储模型</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-%E8%87%AA%E5%8A%A8%E7%B1%BB%E5%9E%8B"><span class="nav-text">4.1 自动类型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-%E5%AF%84%E5%AD%98%E5%99%A8%E7%B1%BB%E5%9E%8B"><span class="nav-text">4.2 寄存器类型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-3-%E9%9D%99%E6%80%81%E7%B1%BB%E5%9E%8B"><span class="nav-text">4.3 静态类型</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#4-3-1%E9%9D%99%E6%80%81%E3%80%81%E7%A9%BA%E9%93%BE%E6%8E%A5"><span class="nav-text">4.3.1静态、空链接</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-3-2-%E9%9D%99%E6%80%81%E3%80%81%E5%86%85%E9%83%A8%E9%93%BE%E6%8E%A5"><span class="nav-text">4.3.2 静态、内部链接</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-4-%E5%A4%96%E9%83%A8%E7%B1%BB%E5%9E%8B"><span class="nav-text">4.4 外部类型</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E5%B8%B8%E9%87%8F"><span class="nav-text">二、常量</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E6%95%B4%E6%95%B0%E5%B8%B8%E9%87%8F"><span class="nav-text">1. 整数常量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%B5%AE%E7%82%B9%E5%B8%B8%E9%87%8F"><span class="nav-text">2. 浮点常量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%AD%97%E7%AC%A6%E5%B8%B8%E9%87%8F"><span class="nav-text">3. 字符常量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E9%87%8F"><span class="nav-text">4. 字符串常量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E5%AE%9A%E4%B9%89%E5%B8%B8%E9%87%8F"><span class="nav-text">5. 定义常量</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#5-1-define-%E5%AE%9A%E4%B9%89%E5%B8%B8%E9%87%8F"><span class="nav-text">5.1 define 定义常量</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-2-const-%E5%AE%9A%E4%B9%89%E5%B8%B8%E9%87%8F"><span class="nav-text">5.2 const 定义常量</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="nav-text">三、运算符</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E7%9B%B8%E5%85%B3%E6%A6%82%E5%BF%B5"><span class="nav-text">1. 相关概念</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E8%BF%90%E7%AE%97%E7%AC%A6%E4%B8%8E%E4%BC%98%E5%85%88%E7%BA%A7"><span class="nav-text">2. 运算符与优先级</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9B%9B%E3%80%81%E4%BD%8D%E9%80%BB%E8%BE%91%E8%BF%90%E7%AE%97"><span class="nav-text">四、位逻辑运算</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%B8%8E%E8%BF%90%E7%AE%97"><span class="nav-text">1. 与运算</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%88%96%E8%BF%90%E7%AE%97"><span class="nav-text">2. 或运算</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E9%9D%9E%E8%BF%90%E7%AE%97"><span class="nav-text">3. 非运算</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E5%BC%82%E6%88%96%E8%BF%90%E7%AE%97"><span class="nav-text">4. 异或运算</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E5%90%8C%E6%88%96%E8%BF%90%E7%AE%97"><span class="nav-text">5. 同或运算</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-%E9%80%BB%E8%BE%91%E8%BF%90%E7%AE%97%E5%BA%94%E7%94%A8"><span class="nav-text">6. 逻辑运算应用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#6-1-%E4%BD%8D%E6%B8%85-0"><span class="nav-text">6.1 位清 0 </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-2-%E4%BD%8D%E7%BD%AE-1"><span class="nav-text">6.2 位置 1 </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-3-%E5%BA%94%E7%94%A8%E5%AE%9E%E4%BE%8B"><span class="nav-text">6.3 应用实例</span></a></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/ce2c2639.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV01-02-C语言-变量与运算符 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV01-02-C语言-变量与运算符
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-01-11 16:29:55" itemprop="dateCreated datePublished" datetime="2022-01-11T16:29:55+08:00">2022-01-11</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/" itemprop="url" rel="index"><span itemprop="name">01HQ课程体系</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV01-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/" itemprop="url" rel="index"><span itemprop="name">LV01-C语言基础</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>9.3k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>34 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是C语言基础——变量与运算符相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV01-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/LV01-02-C%E8%AF%AD%E8%A8%80-%E5%8F%98%E9%87%8F%E4%B8%8E%E8%BF%90%E7%AE%97%E7%AC%A6/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr>    <tr>        <td align="center">SecureCRT</td>        <td align="left">Version 8.7.2 (x64 build 2214)   -   正式版-2020年5月14日</td>      </tr>    <tr>        <td align="center">开发板</td>        <td align="left">正点原子 i.MX6ULL Linux阿尔法开发板</td>      </tr>    <tr>        <td align="center">uboot</td>        <td align="left">NXP官方提供的uboot，NXP提供的版本为uboot-imx-rel_imx_4.1.15_2.1.0_ga(使用的uboot版本为U-Boot 2016.03)</td>      </tr>    <tr>        <td align="center">linux内核</td>        <td align="left">linux-4.15(NXP官方提供)</td>      </tr>    <tr>        <td align="center">STM32开发板</td>        <td align="left">正点原子战舰V3(STM32F103ZET6)</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr><td align="center">参考方向  </td><td align="center">参考原文</td></tr>    <tr><td align="left">---</td><td align="left"><a href="" target="_blank">--- <i class="fa fa-external-link-alt"></i> </a></td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">---</td>        <td align="left">--- <a href="" target="_blank">  <i class="fa fa-external-link-alt"></i></a></td>      </tr></table>
              </div>
            </details>

<h1 id="一、变量"><a href="#一、变量" class="headerlink" title="一、变量"></a><font size=3>一、变量</font></h1><p>前边我们知道，数据都会以二进制的形式存在于内存中，那想要使用这个数据怎么办？现实生活中我们会找一个盒子或者袋子来存放物品，既显得整洁，也方便以后找到。计算机也是这样，我们需要先在内存中找一块区域，规定用它来存放某个数据，并起一个名字，方便以后查找。这块区域的名字，就叫做<strong>变量</strong>。变量在内存空间中的首地址，称为<strong>变量的地址</strong>。</p>
<h2 id="1-变量的定义"><a href="#1-变量的定义" class="headerlink" title="1. 变量的定义"></a><font size=3>1. 变量的定义</font></h2><p>在 C 语言中，声明变量的一般形式是：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;存储类型&gt; &lt;数据类型 &gt; &lt;变量名&gt; ;</span><br></pre></td></tr></table></figure>

<p><strong>【说明】</strong></p>
<table>
    <tr>
        <td align="center" width=100px>存储类型</td>
        <td align="left">有四种，分别是auto、register、static和extern</td>
    </tr>
    <tr>
        <td align="center" width=100px>数据类型</td>
        <td align="left">可以是基本数据类型，也可以是自定义的数据类型</td>
    </tr>
    <tr>
        <td align="center" width=100px>变量名</td>
        <td align="left">由字母、数字、下划线组成，不能以数字开头，不能和C语言的关键字重名。</td>
    </tr>
</table>
例如，

<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> a;  <span class="comment">/* 声明了一个整型变量 a */</span></span><br><span class="line"><span class="type">char</span> b; <span class="comment">/* 声明了一个字符型变量 b */</span></span><br></pre></td></tr></table></figure>

<p><strong>【注意】</strong></p>
<p>（1）变量在声明的时候可以一次声明多个。例如，</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> a, b, c;</span><br></pre></td></tr></table></figure>

<p>（2）声明变量是一条语句，注意后边的分号( ; )不可缺少。</p>
<h2 id="2-变量的使用"><a href="#2-变量的使用" class="headerlink" title="2. 变量的使用"></a><font size=3>2. 变量的使用</font></h2><h3 id="2-1-变量的引用"><a href="#2-1-变量的引用" class="headerlink" title="2.1 变量的引用"></a><font size=3>2.1 变量的引用</font></h3><p>当我们想要使用一个变量的时候，就<strong>直接使用变量名</strong>即可。例如，</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">(<span class="type">int</span> argc, <span class="type">const</span> <span class="type">char</span> *argv[])</span> </span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">int</span> a;</span><br><span class="line">	</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;a = %d\n&quot;</span>, a);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>此时在命令行执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">gcc test.c -Wall # 编译程序</span><br></pre></td></tr></table></figure>

<p>这个时候会发现程序有警告：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">test.c:7:2: warning: ‘a’ is used uninitialized in this function [-Wuninitialized]</span><br></pre></td></tr></table></figure>

<p>说的就是这个变量没有进行初始化，下边我们就来看一看如何初始化变量。</p>
<h3 id="2-2-变量的赋值"><a href="#2-2-变量的赋值" class="headerlink" title="2.2 变量的赋值"></a><font size=3>2.2 变量的赋值</font></h3><p>我们上边仅仅是定义了一个变量，还没有放数据进去，在编译的时候就报了警告。变量的赋值有两种方式：</p>
<div class="tabs" id="tabname1"><ul class="nav-tabs"><li class="tab active"><a href="#tabname1-1">赋值方式一</a></li><li class="tab"><a href="#tabname1-2">赋值方式二</a></li></ul><div class="tab-content"><div class="tab-pane active" id="tabname1-1"><ul>
<li>在声明变量之后再进行单独赋值</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">(<span class="type">int</span> argc, <span class="type">const</span> <span class="type">char</span> *argv[])</span> </span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">int</span> a;</span><br><span class="line">	a = <span class="number">10</span>;</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;a = %d\n&quot;</span>, a);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>此时在终端执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">gcc test.c -Wall # 编译程序</span><br><span class="line">./a.out          # 执行可执行文件</span><br></pre></td></tr></table></figure>

<p>这个时候会发现终端有以下信息输出：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">a = 10</span><br></pre></td></tr></table></figure></div><div class="tab-pane" id="tabname1-2"><ul>
<li>在声明变量的同时进行赋值</li>
</ul>
<p>这也被称为<strong>变量的初始化</strong>。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">(<span class="type">int</span> argc, <span class="type">const</span> <span class="type">char</span> *argv[])</span> </span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">int</span> a = <span class="number">10</span>;</span><br><span class="line"></span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;a = %d\n&quot;</span>, a);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>此时在终端执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">gcc test.c -Wall # 编译程序</span><br><span class="line">./a.out          # 执行可执行文件</span><br></pre></td></tr></table></figure>

<p>这个时候会发现终端有以下信息输出：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">a = 10</span><br></pre></td></tr></table></figure>

<p>其实下边的写法是等价的</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> a = <span class="number">10</span></span><br><span class="line"><span class="comment">// 等价于</span></span><br><span class="line"><span class="type">int</span> a;</span><br><span class="line">a = <span class="number">10</span>;</span><br></pre></td></tr></table></figure></div></div></div>

<h2 id="3-变量的作用域"><a href="#3-变量的作用域" class="headerlink" title="3. 变量的作用域"></a><font size=3>3. 变量的作用域</font></h2><p>变量作用域的定义：程序中可以访问一个指示符的一个或者多个区域，即变量出现的有效区域决定了程序的哪些部分通过变量名来访问变量。其实我自己的理解就是：作用域就是这个变量的生存区域，在这个区域内变量有效，区域外变量无法访问。</p>
<h3 id="3-1-变量作用域类别"><a href="#3-1-变量作用域类别" class="headerlink" title="3.1 变量作用域类别"></a><font size=3>3.1 变量作用域类别</font></h3><ul>
<li><strong>（1）函数原型作用域</strong></li>
</ul>
<p>它指的是在<strong>声明函数原型时所指定的参数标识符的作用范围</strong>。因为作用范围是小括号内，所以函数原型声明中的标识符可以与函数定义中说明的标识符名称不同。只要让函数声明和函数定义中小括号内每个变量的类型及数目一致即可，也可以省略掉参数名（函数定义在后，调用在前），例如，</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">func</span><span class="params">(<span class="type">int</span> a, <span class="type">char</span> b)</span>;</span><br></pre></td></tr></table></figure>

<ul>
<li><strong>（2）块作用域</strong></li>
</ul>
<p>块作用域也称为局部作用域，也就是语句块的作用域。一般在函数中起到分割的作用。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="type">int</span> a = <span class="number">5</span>; <span class="comment">/* a的作用域起始处 */</span></span><br><span class="line">    <span class="keyword">if</span>(a &gt; <span class="number">0</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="type">int</span> b; <span class="comment">/* b的作用域起始处 */</span></span><br><span class="line">        b = a - <span class="number">3</span>;</span><br><span class="line">    &#125; <span class="comment">/* b的作用域结束处 */</span></span><br><span class="line">&#125;<span class="comment">/* a的作用域结束处 */</span></span><br></pre></td></tr></table></figure>

<ul>
<li><strong>（3）函数作用域</strong></li>
</ul>
<p>在函数内部定义的一些变量，只能在函数内部使用，一旦离开了这个函数，就必须重新定义。其实可以把函数看做一个块，然后根据作用域的定义。例如，</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">func</span><span class="params">(<span class="type">int</span> x, <span class="type">int</span> y)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">int</span> a = <span class="number">5</span>; <span class="comment">/* a的作用域起始处 */</span></span><br><span class="line">    <span class="keyword">if</span>(a &gt; <span class="number">0</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="type">int</span> b; <span class="comment">/* b的作用域起始处 */</span></span><br><span class="line">        b = a - <span class="number">3</span>;</span><br><span class="line">    &#125; <span class="comment">/* b的作用域结束处 */</span></span><br><span class="line">&#125;<span class="comment">/* a的作用域结束处 */</span></span><br></pre></td></tr></table></figure>

<ul>
<li><strong>（4）文件作用域</strong></li>
</ul>
<p>在所有函数外定义的标识符称为全局标识符，定义的变量称为<strong>全局变量</strong>。全局标识符的作用域是文件作用域，即从它声明开始到文件结束都是可见的。标识符的文件作用域一般有三种情况：</p>
<p>①、全局常量或全局变量的作用域是从定义开始到源程序文件结束。例如，</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> a = <span class="number">10</span>;</span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">// ... ...</span></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>②、函数的定义中包含了函数声明，所以一旦声明了函数原型，函数标识符的作用域就从定义开始到源程序文件结束。例如，</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">func1</span><span class="params">()</span>;  <span class="comment">/* 函数 fun1 的作用域从此开始到文件结束 */</span></span><br><span class="line"><span class="type">int</span> <span class="title function_">func2</span><span class="params">()</span>   <span class="comment">/* 函数 fun2 的作用域从此开始到文件结束 */</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">// ... ...</span></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">// ... ...</span></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">func1</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">// ... ...</span></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>③、还有一种在头文件中定义的标识符，预编译时，编译器会将头文件的内容在源文件的相应位置展开，所以在头文件中定义的标识符的作用域可以看成从 #include 头文件开始的位置到源程序文件结束。</p>
<h3 id="3-2-作用域的重叠会发生什么？"><a href="#3-2-作用域的重叠会发生什么？" class="headerlink" title="3.2 作用域的重叠会发生什么？"></a><font size=3>3.2 作用域的重叠会发生什么？</font></h3><p>当<strong>标识符的作用域完全相同时，不允许出现相同的标识符名</strong>，而当<strong>标识符有不同作用域时允许标识符同名</strong>。如果是作用域嵌套的情况下，如果内层和外层的作用域声明了同名的标识符，那么在外层作用域中声明的标识符对于该内层作用域时不可见的。也就是说，在内层中声明的变量 i 和外层变量 i 无关，当内层变量改变时，与之同名的外层变量的值不受影响。例如</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">(<span class="type">int</span> argc, <span class="type">char</span> *argv[])</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">int</span> a = <span class="number">5</span>;</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="type">int</span> a = <span class="number">7</span>;</span><br><span class="line">		<span class="built_in">printf</span>(<span class="string">&quot;in&#123;&#125; :a=%d\n&quot;</span>, a);</span><br><span class="line">		a = <span class="number">10</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;out&#123;&#125;: a=%d\n&quot;</span>, a);</span><br><span class="line"></span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>我们编译后运行，会得到以下输出情况：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">in&#123;&#125; :a=7</span><br><span class="line">out&#123;&#125;: a=5</span><br></pre></td></tr></table></figure>

<h3 id="3-3-不同存储类型变量的作用域"><a href="#3-3-不同存储类型变量的作用域" class="headerlink" title="3.3 不同存储类型变量的作用域"></a><font size=3>3.3 不同存储类型变量的作用域</font></h3><table>
<thead>
<tr>
<th><strong>存储类别</strong></th>
<th><strong>存储期</strong></th>
<th><strong>作用域</strong></th>
<th><strong>声明方式</strong></th>
</tr>
</thead>
<tbody><tr>
<td>auto</td>
<td>动态</td>
<td>块</td>
<td>块内</td>
</tr>
<tr>
<td>register</td>
<td>动态</td>
<td>块</td>
<td>块内，使用关键字 register</td>
</tr>
<tr>
<td>static(局部)</td>
<td>静态</td>
<td>块</td>
<td>块内，使用关键字 static</td>
</tr>
<tr>
<td>static(全局)</td>
<td>静态</td>
<td>文件内部</td>
<td>所有函数外，使用关键字 static</td>
</tr>
<tr>
<td>extern</td>
<td>静态</td>
<td>文件外部</td>
<td>所有函数外</td>
</tr>
</tbody></table>
<h2 id="4-变量的存储模型"><a href="#4-变量的存储模型" class="headerlink" title="4. 变量的存储模型"></a><font size=3>4. 变量的存储模型</font></h2><p>变量是程序中数据的存储空间的抽象。变量的存储方式（也可以被称之为<strong>存储期</strong>）可分为<strong>静态存储</strong>和<strong>动态存储</strong>两种：</p>
<ul>
<li>静态存储变量，通常是在程序编译时就分配一定的存储空间并一直保特不变，直至整个程序结束。全局变量的存储方式就属于这种存储方式 </li>
<li>动态存储变量，是在程序执行过程中使用它时才分配存储空间，使用完毕的时候内存空间将会被立即释放。</li>
</ul>
<p>变量的<strong>存储类型</strong>大概分为四种：<strong>自动类型</strong>、<strong>寄存器类型</strong>、<strong>静态类型</strong>和<strong>外部类型</strong>。变量的存储模型若由<strong>作用域</strong>、链接点和<strong>存储期</strong>（存储期描述的是变量在内存中的生存时间）三大属性来描述的话，变量的存储模型可以分为五种，这五种其实就相当于把四种存储类型细分了，下边将详细介绍。</p>
<h3 id="4-1-自动类型"><a href="#4-1-自动类型" class="headerlink" title="4.1 自动类型"></a><font size=3>4.1 自动类型</font></h3><p>自动变量就是指<strong>非静态局部变量</strong>，自动变量声明的语法格式为</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[<span class="keyword">auto</span>] 数据类型 变量名;</span><br></pre></td></tr></table></figure>

<p> auto 为存储类说明符，它是可选的，一般我们会选择省略。说明这个变量为自动变量，这种自动变量具有<strong>动态存储期</strong>、代码块的作用域和<strong>空链接</strong>。</p>
<ul>
<li>自动变量的特点</li>
</ul>
<p>（1）自动变量的<strong>作用域仅限于定义该变量的模块内</strong>。在函数中定义的自动变量，只在该函数内有效。在复合语句中定义的自动变量，只在该复合语句中有效。</p>
<p>（2）自动变量属于<strong>动态存储方式</strong>，只有在定义该变量的函数被调用时才给它分配存储单元，开始它的生存期。函数调用结束，释放存储单元，结束生存期。因此函数调用结束之后，自动变量的值不能保留。在复合语句中定义的自动变量，在退出复合语句后也不能再使用，否则将引起错误。</p>
<p>（3）由于自动变量的作用域和生存期都局限于定义它的模块内（函数或复合语句内），因此<strong>不同的模块中允许使用同名的变量</strong>而不会混淆。即使在函数内定义的自动变量也可与该函数内部的复合语句中定义的自动变量同名，但我们应尽量避免使用这种方式。</p>
<p><strong>【注意】</strong></p>
<p>（1）代码块或者函数头部定义的变量，可以使用存储类修饰符 auto 来明确标识属于自动存储类型。若没有 auto 修饰，默认也是自动类型。</p>
<p>（2） auto 型变量如果<strong>没有进行初始化，那么它默认是随机值</strong>。</p>
<h3 id="4-2-寄存器类型"><a href="#4-2-寄存器类型" class="headerlink" title="4.2 寄存器类型"></a><font size=3>4.2 寄存器类型</font></h3><p>在一个代码块内（或在一个函数头部作为参量）使用修饰符 register 声明的变量属于<strong>寄存器存储类</strong>。一般声明格式为：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">register</span> 数据类型 变量名;</span><br></pre></td></tr></table></figure>

<p>register 修饰符暗示编译程序相应的变量<strong>将被频繁使用</strong>，如果可能的话，应将其保存在 CPU 的寄存器中，从而加快其存取速度。该类与自动存储类相似，具有<strong>自动存储期</strong>、代码块作用域和<strong>空链接</strong>。</p>
<ul>
<li>使用 register 修饰符有几点限制：</li>
</ul>
<p>（1） register 变量必须是能被 CPU 寄存器所接受的类型，这通常意味者 register 变量必须是一个单个的值，并且其长度应小于或等于整型的长度，这与处理器的类型有关。</p>
<p>（2）声明为 register 仅仅是一个请求，而非命令，因此变量仍然可能是普通的自动变量，没有放在寄存器中。</p>
<p>（3）只有局部变量和形参可以作为 register 变量，全局变量不行：</p>
<p>（4）实际上有些系统并不把 register 变量存放在奇存器中，而优化的编译系统则可以自动识别使用频繁的变量而把它们放在奇存器中。</p>
<p><strong>【注意】</strong></p>
<p>（1）不能用 &amp; 来获取 register 变量的地址。</p>
<p>（2） register 型变量<strong>如果没有进行初始化，那么它默认是随机值</strong>。</p>
<h3 id="4-3-静态类型"><a href="#4-3-静态类型" class="headerlink" title="4.3 静态类型"></a><font size=3>4.3 静态类型</font></h3><p>静态变量的类型说明符是 static 。它分为两种，一种是静态局部变量（静态、空链接），一种是静态全局变量（静态、内部链接）。静态局部变量属于静态存储方式。</p>
<h4 id="4-3-1静态、空链接"><a href="#4-3-1静态、空链接" class="headerlink" title="4.3.1静态、空链接"></a><font size=3>4.3.1静态、空链接</font></h4><p>在一个<strong>代码块</strong>内使用存储类修饰符 static 声明的局部变量属于静态空链接存储类。该类具有<strong>静态存储期</strong>、代码块作用域和<strong>空链接</strong>。一般格式如下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">func</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">static</span> 数据类型 变量名;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>静态变量的存储空间是在编译完成后就分配了，并且在程序运行的全部过程中都不会撤销。但是<strong>属于静态存储方式的变量不一定就是静态变量</strong>。例如，外部变量虽属于静态存储方式，但不一定是静态变量，必须由 static 加以定义后才能称为静态外部变量，或称静态全局变量。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV01-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/LV01-02-C%E8%AF%AD%E8%A8%80-%E5%8F%98%E9%87%8F%E4%B8%8E%E8%BF%90%E7%AE%97%E7%AC%A6/img/image-20220402162636518.png" alt="image-20220402162636518" style="zoom: 33%;" />

<p>静态局部变量在函数内定义，它的生存期为整个程序执行期间，但是其<strong>作用域仍与自动变量相同</strong>，只能在定义该变量的函数内使用该变量。退出该函数后，尽管该变量还继续存在，但不能使用它。静态局部变量生存周期与作用域如下图：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV01-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/LV01-02-C%E8%AF%AD%E8%A8%80-%E5%8F%98%E9%87%8F%E4%B8%8E%E8%BF%90%E7%AE%97%E7%AC%A6/img/image-20220402163051101.png" alt="image-20220402163051101" style="zoom: 33%;" />

<p>根据静态局部变量的特点，可以看出它是一种生存期为整个程序运行期的变量。虽然离开定义它的函数后不能使用，但如再次调用定义它的函数时，它又可以继续使用，并且保留了上次被调用后的值。因此，当多次调用一个函数且要求在调用之前保留某些变量的值时，可以考虑采用静态局部变量。虽然用全局变量也可以达到上述目的，但全局变量有时会造成意外的副作用，因此仍以采用静态局部变量更好些。</p>
<p><strong>【注意】</strong></p>
<p>（1）可以对构造类静态局部量赋初值，例如数组。若未赋初值，则由<strong>系统自动初始化</strong>为 0 。基本数据类型的静态局部变量若在说明时未赋初值，则<strong>系统自动</strong>赋予 0 。</p>
<h4 id="4-3-2-静态、内部链接"><a href="#4-3-2-静态、内部链接" class="headerlink" title="4.3.2 静态、内部链接"></a><font size=3>4.3.2 静态、内部链接</font></h4><p>全局变量在关键字之前再加上 static 就构成了静态的全局变量，属于静态、内部链接存储类。与静态、外部链接存储类不同的是，具有内部链接，使得这<strong>种变量仅能被与它在同一个文件的函数使用</strong>。一般格式如下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">static</span> 数据类型 变量名;</span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>这样的变量也是只会在在编译时初始化一次。如若未明确初始化，它的初始值被设定为 0 。</p>
<p>非静态全局变量的作用域是整个源程序，但当一个源程序由多个源文件组成时，非静态的全局变量在各个源文件中都是有效的；而静态全局变量则限制了其作用域，即只在定义该变量的源文件内有效，在同一源程序的其他源文件中不能使用。由于静态全局变量的作用域局限于一个源文件内，只能被该源文件内的函数使用，因此可以避免在其他源文件中引起错误。两者作用域区别如下图：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV01-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/LV01-02-C%E8%AF%AD%E8%A8%80-%E5%8F%98%E9%87%8F%E4%B8%8E%E8%BF%90%E7%AE%97%E7%AC%A6/img/image-20220402165150484.png" alt="image-20220402165150484" style="zoom:50%;" />

<h3 id="4-4-外部类型"><a href="#4-4-外部类型" class="headerlink" title="4.4 外部类型"></a><font size=3>4.4 外部类型</font></h3><p>未使用 static 修饰的全局变量属于静态、外部链接存储类。具有<strong>静态存储期</strong>、<strong>文件作用域</strong>和<strong>外链接</strong>。一般格式如下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">数据类型 变量名;</span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>只会在在编译时初始化一次。如若未明确初始化，它的初始值也被设定为 0 。在使用外部变量的函数中使 extern 关键字来再次声明。如果是在其他文件中定义的，则必须使用 extern 。</p>
<h1 id="二、常量"><a href="#二、常量" class="headerlink" title="二、常量"></a><font size=3>二、常量</font></h1><p>上边介绍了变量，接下来看一看常量吧。常量是固定值，在程序执行期间不会改变。这些固定的值，又叫做<strong>字面量</strong>。需要注意的常量一旦定义，是<strong>不可以被修改</strong>的。</p>
<h2 id="1-整数常量"><a href="#1-整数常量" class="headerlink" title="1. 整数常量"></a><font size=3>1. 整数常量</font></h2><p>整数常量可以是十进制、八进制或十六进制的常量。前缀指定基数： 0x  或  0X  表示十六进制， 0  表示八进制，不带前缀则默认表示十进制。</p>
<p>整数常量也可以带一个后缀，后缀是  U  和  L  的组合， U  表示无符号整数（ unsigned ）， L  表示长整数（ long ）。后缀可以是大写，也可以是小写， U  和  L  的顺序任意。</p>
<details class="folding-tag" blue><summary> 点击查看实例 </summary>
              <div class='content'>
              <table>    <tr><td align="center">75</td><td align="left">十进制</td></tr>    <tr><td align="center">0253</td><td align="left">八进制</td></tr>    <tr><td align="center">0x4b</td><td align="left">十六进制</td></tr>    <tr><td align="center">50</td><td align="left">整数</td></tr>    <tr><td align="center">50u</td><td align="left">无符号整数</td></tr>    <tr><td align="center">50l</td><td align="left">长整数</td></tr>    <tr><td align="center">50ul</td><td align="left">无符号长整数</td></tr></table>
              </div>
            </details>

<h2 id="2-浮点常量"><a href="#2-浮点常量" class="headerlink" title="2. 浮点常量"></a><font size=3>2. 浮点常量</font></h2><p>浮点常量由整数部分、小数点、小数部分和指数部分组成。我们可以使用<strong>小数形式</strong>或者<strong>指数形式</strong>来表示浮点常量。使用小数形式表示时，必须包含整数部分、小数部分，或同时包含两者。当使用指数形式表示时， 必须包含小数点、指数，或同时包含两者。一般格式如下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[+ or -]&lt;整数部分&gt;&lt;小数点&gt;&lt;小数部分&gt;&lt;e或者E&gt;[+ or -]&lt;指数&gt;</span><br></pre></td></tr></table></figure>

<p>例如：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">3.14159</span>       <span class="comment">/* 正确的 */</span></span><br><span class="line"><span class="number">314159E-5</span>L    <span class="comment">/* 正确的 */</span></span><br><span class="line"><span class="number">-3.14e18</span>      <span class="comment">/* 正确的 */</span></span><br><span class="line">    </span><br><span class="line"><span class="number">510</span>E          <span class="comment">/* 错误的：不完整的指数 */</span></span><br><span class="line"><span class="number">210f</span>          <span class="comment">/* 错误的：没有小数或指数 */</span></span><br><span class="line">.e55          <span class="comment">/* 错误的：缺少整数或分数 */</span></span><br></pre></td></tr></table></figure>

<h2 id="3-字符常量"><a href="#3-字符常量" class="headerlink" title="3. 字符常量"></a><font size=3>3. 字符常量</font></h2><p>字符常量是指用单引号 ‘ ‘ 括起来的一个字符，例如 ‘a’ 、 ‘b’ 等。C 语言中还存在一种特殊的字符常量——转义字符。转义字符以反斜线 \ 开头，后跟一个或几个字符。转义字符具有特定的含义，不同于字符原有的意义，故称“转义”字符。</p>
<details class="folding-tag" blue><summary> 点击查看常用转义字符 </summary>
              <div class='content'>
              <table>    <tr><td align="center">转义字符</td><td align="left">含义</td></tr>    <tr><td align="center">\a</td><td align="left">警报铃声</td></tr>    <tr><td align="center">\b</td><td align="left">退格键</td></tr>    <tr><td align="center">\f</td><td align="left">换页符，将当前位置移动到下页开头</td></tr>    <tr><td align="center">\n</td><td align="left">换行符</td></tr>    <tr><td align="center">\r</td><td align="left">回车</td></tr>    <tr><td align="center">\t</td><td align="left">水平制表符</td></tr>    <tr><td align="center">\v</td><td align="left">垂直制表符</td></tr>    <tr><td align="center">\ooo</td><td align="left">1~3位八进制数所代表的字符</td></tr>    <tr><td align="center">\xhh</td><td align="left">1~2位十六进制数所代表的字符</td></tr>    <tr><td align="center">\\</td><td align="left">\ 字符</td></tr></table>
              </div>
            </details>

<p>【注意】</p>
<p>（1）字符常量只能用单引号括起来，不能用双引号或其他括号。</p>
<p>（2）字符常量只能是单个字符，不能是字符串。</p>
<p>（3）字符可以是字符集中任意字符。但数字被定义为字符型之后就不能参与数值运算。例如 5 和 ‘5’ 是不同的， ‘5’ 是字符常量，不能直接参与运算，而只能以其 ASCII 码值（ 053 ）来参与运算。</p>
<h2 id="4-字符串常量"><a href="#4-字符串常量" class="headerlink" title="4. 字符串常量"></a><font size=3>4. 字符串常量</font></h2><p>字符串常量是指用一对双引号( “ “ )括起来的一串字符，双引号只起定界作用，双引号括起的字符串中不能是双引号（ “ “ ）和反斜杠（ \ ）。例如 “YES&amp;NO” 、 “2-21” 和 “a” 等都是合格的字符串常量。在 C 语言中，字符串常量在内存中存储时系统自动在字符串的末尾加一个字符串结束标志，即 ASCII 值为 0 的字符 NULL ，通常用 \0 表示。</p>
<p><strong>【注意】</strong>在 C 语言中，长度为 n 个字符的字符串常量在内存中占有 n + 1 个字节的存储空间。例如，</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&#x27;a&#x27;</span>  这是一个字符常量，占用一个字节空间</span><br><span class="line"><span class="string">&quot;a&quot;</span>  这是一个字符串常量，占用两个字节空间(多了一个<span class="string">&#x27;\0&#x27;</span>)</span><br></pre></td></tr></table></figure>

<h2 id="5-定义常量"><a href="#5-定义常量" class="headerlink" title="5. 定义常量"></a><font size=3>5. 定义常量</font></h2><h3 id="5-1-define-定义常量"><a href="#5-1-define-定义常量" class="headerlink" title="5.1 define 定义常量"></a><font size=3>5.1 define 定义常量</font></h3><p> define 是一个预处理关键字，它的实际用途大于定义常量这一功能，其他的功能后边还会详细解释。通过 define 定义常量的一般格式为：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">define</span> identifier value</span></span><br></pre></td></tr></table></figure>

<ul>
<li>identifier 为符号名，必须符合标识符的命名规则。</li>
<li>value 为替换列表，可以是任意的字符序列，如数字、字符、字符串、表达式等。</li>
</ul>
<p>例如，</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">define</span> LENGTH 10   </span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> WIDTH 5</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> BEEP <span class="string">&#x27;\a&#x27;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> MSG <span class="string">&quot;Hello World!&quot;</span></span></span><br></pre></td></tr></table></figure>

<h3 id="5-2-const-定义常量"><a href="#5-2-const-定义常量" class="headerlink" title="5.2 const 定义常量"></a><font size=3>5.2 const 定义常量</font></h3><p> const 是 C 语言中的一个关键字，可以借助该关键字来定义常量，创建常量的格式如下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">const</span> dataType name = value;</span><br></pre></td></tr></table></figure>

<table>
    <tr>
        <td align="center" width=100px>const</td>
        <td align="left">定义常量的关键字</td>
    </tr>
    <tr>
        <td align="center" width=100px>dataType</td>
        <td align="left">数据类型，基本数据类型都可以，如int、char、float等</td>
    </tr>
    <tr>
        <td align="center" width=100px>name</td>
        <td align="left">常量名称</td>
    </tr>
    <tr>
        <td align="center" width=100px>value</td>
        <td align="left">常量的值</td>
    </tr>
</table>
**【注意】**

<p>（1） const 和  dataType 位置可以互换，例如，</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">const</span> <span class="type">int</span> a = <span class="number">10</span>;</span><br><span class="line"><span class="type">int</span> <span class="type">const</span> a = <span class="number">10</span>;</span><br></pre></td></tr></table></figure>

<p>上边两种定义等价，但是一般推荐 const 在前。</p>
<p>（2）由于<strong>常量一旦被创建后其值就不能再改变</strong>，所以常量必须<strong>在定义的同时赋值（初始化）</strong>，后面的任何赋值行为都将引发错误。</p>
<h1 id="三、运算符"><a href="#三、运算符" class="headerlink" title="三、运算符"></a><font size=3>三、运算符</font></h1><h2 id="1-相关概念"><a href="#1-相关概念" class="headerlink" title="1. 相关概念"></a><font size=3>1. 相关概念</font></h2><p> C 语言中表示运算的符号称为<strong>运算符</strong>，运算的对象称为<strong>操作数</strong>。对一个操作数进行运算的运算符称为<strong>单目运算符</strong>，对两个操作数进行运算的运算符称为<strong>双目运算符</strong>，<strong>三目运算符</strong>是对三个操作数进行运算。用运算符和括号可以将操作数连接起来组成<strong>表达式</strong>。</p>
<h2 id="2-运算符与优先级"><a href="#2-运算符与优先级" class="headerlink" title="2. 运算符与优先级"></a><font size=3>2. 运算符与优先级</font></h2><details class="folding-tag" blue><summary> 点击查看运算符及其优先级 </summary>
              <div class='content'>
              <table>    <tr >        <td align="center" width=80px>优先级</td>        <td align="center" width=80px>运算符</td>        <td align="center">名称(含义)</td>        <td align="center">使用形式</td>        <td align="center">结合规律</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center" width=80px rowspan="4">1</td>        <td align="center" width=80px>[]</td>        <td align="left">数组下标</td>        <td align="left">数组名称[常量表达式]</td>        <td align="center" rowspan="4">左&rarr;右</td>        <td align="center">——</td>    </tr>    <tr>        <td align="center" width=80px>()</td>        <td align="left">圆括号</td>        <td align="left">(表达式）<br>函数名(形参表)</td>        <td align="center">——</td>    </tr>    <tr>        <td align="center" width=80px>.</td>        <td align="left">成员选择(对象)</td>        <td align="left">对象.成员名</td>        <td align="center">——</td>    </tr>    <tr>        <td align="center" width=80px>-></td>        <td align="left">成员选择(指针)</td>        <td align="left">对象指针->成员名</td>        <td align="center">——</td>    </tr>    <tr><!-- 1 -->        <td align="center" width=80px rowspan="9">2</td>        <td align="center" width=80px>-</td>        <td align="left">负号运算符</td>        <td align="left">-表达式</td>        <td align="center" rowspan="9"  style="color: red">左&larr;右</td>        <td align="center" rowspan="7">单目运算符</td>    </tr>    <tr><!-- 2 -->        <td align="center" width=80px>~</td>        <td align="left">按位取反运算符</td>        <td align="left">~表达式</td>    </tr>    <tr><!-- 3 -->        <td align="center" width=80px>++</td>        <td align="left">自增运算符</td>        <td align="left">++变量名<br>变量名++</td>    </tr>    <tr> <!-- 4 -->        <td align="center" width=80px>--</td>        <td align="left">自减运算符</td>        <td align="left">--变量名<br>变量名--</td>    </tr>    <tr><!-- 5 -->        <td align="center" width=80px>*</td>        <td align="left">取值运算符(指针运算符)</td>        <td align="left">*指针变量</td>    </tr>    <tr><!-- 6 -->        <td align="center" width=80px>&</td>        <td align="left">取地址运算符</td>        <td align="left">&变量名</td>    </tr>    <tr><!-- 7 -->        <td align="center" width=80px>!</td>        <td align="left">逻辑非运算符</td>        <td align="left">!表达式</td>    </tr>    <tr><!-- 8 -->        <td align="center" width=80px>(类型)</td>        <td align="left">强制类型转换</td>        <td align="left">(数据类型)表达式</td>        <td align="center">——</td>    </tr>    <tr><!-- 9 -->        <td align="center" width=80px>sizeof</td>        <td align="left">长度运算符</td>        <td align="left">sizeof(表达式)</td>        <td align="center">——</td>    </tr>    <tr><!-- 1 -->        <td align="center" width=80px rowspan="3">3</td>        <td align="center" width=80px>*</td>        <td align="left">乘法运算符</td>        <td align="left">表达式 * 表达式</td>        <td align="center" rowspan="3">左&rarr;右</td>        <td align="center" rowspan="3">双目运算符</td>    </tr>    <tr><!-- 2 -->        <td align="center" width=80px>/</td>        <td align="left">除法运算符</td>        <td align="left">表达式 / 表达式</td>    </tr>    <tr><!-- 3 -->        <td align="center" width=80px>%</td>        <td align="left">求余运算符(取模)</td>        <td align="left">整型表达式 % 整型表达式</td>    </tr>    <tr><!-- 1 -->        <td align="center" width=80px rowspan="2">4</td>        <td align="center" width=80px>+</td>        <td align="left">加法运算符</td>        <td align="left">表达式 + 表达式</td>        <td align="center" rowspan="2">左&rarr;右</td>        <td align="center" rowspan="2">双目运算符</td>    </tr>    <tr><!-- 2 -->        <td align="center" width=80px>-</td>        <td align="left">减法运算符</td>        <td align="left">表达式 - 表达式</td>    </tr>    <tr><!-- 1 -->        <td align="center" width=80px rowspan="2">5</td>        <td align="center" width=80px> &lt;&lt; </td>        <td align="left">左移运算符</td>        <td align="left">变量 &lt;&lt; 表达式</td>        <td align="center" rowspan="2">左&rarr;右</td>        <td align="center" rowspan="2">双目运算符</td>    </tr>    <tr><!-- 2 -->        <td align="center" width=80px> &gt;&gt; </td>        <td align="left">右移运算符</td>        <td align="left">变量 &gt;&gt; 表达式</td>    </tr>    <tr><!-- 1 -->        <td align="center" width=80px rowspan="4">6</td>        <td align="center" width=80px> &gt; </td>        <td align="left">大于</td>        <td align="left">表达式 &gt; 表达式</td>        <td align="center" rowspan="4">左&rarr;右</td>        <td align="center" rowspan="4">双目运算符</td>    </tr>    <tr><!-- 2 -->        <td align="center" width=80px>  &gt;= </td>        <td align="left">大于等于</td>        <td align="left">表达式 &gt;= 表达式</td>    </tr>    <tr><!-- 3 -->        <td align="center" width=80px>  &lt; </td>        <td align="left">小于</td>        <td align="left">表达式 &lt; 表达式</td>    </tr>    <tr><!-- 4 -->        <td align="center" width=80px>  &lt;= </td>        <td align="left">小于等于</td>        <td align="left">表达式 &lt;= 表达式</td>    </tr>    <tr><!-- 1 -->        <td align="center" width=80px rowspan="2">7</td>        <td align="center" width=80px> == </td>        <td align="left">等于运算符</td>        <td align="left">表达式 == 表达式</td>        <td align="center" rowspan="2">左&rarr;右</td>        <td align="center" rowspan="2">双目运算符</td>    </tr>    <tr><!-- 2 -->        <td align="center" width=80px>  !== </td>        <td align="left">不等于运算符</td>        <td align="left">表达式 !== 表达式</td>    </tr>    <tr>        <td align="center" width=80px>8</td>        <td align="center" width=80px>  & </td>        <td align="left">按位与运算符</td>        <td align="left">表达式 & 表达式</td>        <td align="center">左&rarr;右</td>        <td align="center">双目运算符</td>    </tr>    <tr>        <td align="center" width=80px>9</td>        <td align="center" width=80px>  ^ </td>        <td align="left">按位异或运算符</td>        <td align="left">表达式 ^ 表达式</td>        <td align="center">左&rarr;右</td>        <td align="center">双目运算符</td>    </tr>    <tr>        <td align="center" width=80px>10</td>        <td align="center" width=80px>  | </td>        <td align="left">按位或运算符</td>        <td align="left">表达式 | 表达式</td>        <td align="center">左&rarr;右</td>        <td align="center">双目运算符</td>    </tr>    <tr>        <td align="center" width=80px>11</td>        <td align="center" width=80px>  && </td>        <td align="left">逻辑与运算符</td>        <td align="left">表达式 && 表达式</td>        <td align="center">左&rarr;右</td>        <td align="center">双目运算符</td>    </tr>    <tr>        <td align="center" width=80px>12</td>        <td align="center" width=80px>  || </td>        <td align="left">逻辑或运算符</td>        <td align="left">表达式 || 表达式</td>        <td align="center">左&rarr;右</td>        <td align="center">双目运算符</td>    </tr>    <tr>        <td align="center" width=80px>13</td>        <td align="center" width=80px>  ? : </td>        <td align="left">条件运算符</td>        <td align="left">表达式1 ? 表达式2 : 表达式3</td>        <td align="center"  style="color: red">左&larr;右</td>        <td align="center">三目运算符</td>    </tr>    <tr><!-- 1 -->        <td align="center" width=80px rowspan="11">14</td>        <td align="center" width=80px>=</td>        <td align="left">赋值运算符</td>        <td align="left">变量 = 表达式</td>        <td align="center" rowspan="11"  style="color: red">左&larr;右</td>        <td align="center">——</td>    </tr>    <tr><!-- 2 -->        <td align="center" width=80px>/=</td>        <td align="left">除后赋值运算符</td>        <td align="left">变量 /= 表达式</td>        <td align="center">——</td>    </tr>    <tr><!-- 3 -->        <td align="center" width=80px>*=</td>        <td align="left">乘后赋值运算符</td>        <td align="left">变量 *= 表达式</td>        <td align="center">——</td>    </tr>    <tr><!-- 4 -->        <td align="center" width=80px>%=</td>        <td align="left">取模后赋值运算符</td>        <td align="left">变量 %= 表达式</td>        <td align="center">——</td>    </tr>    <tr><!-- 5 -->        <td align="center" width=80px>+=</td>        <td align="left">加后赋值运算符</td>        <td align="left">变量 += 表达式</td>        <td align="center">——</td>    </tr>    <tr><!-- 6 -->        <td align="center" width=80px>-=</td>        <td align="left">减后赋值运算符</td>        <td align="left">变量 -= 表达式</td>        <td align="center">——</td>    </tr>    <tr><!-- 7 -->        <td align="center" width=80px>&lt;&lt;=</td>        <td align="left">左移后赋值运算符</td>        <td align="left">变量 &lt;&lt;= 表达式</td>        <td align="center">——</td>    </tr>    <tr><!-- 8 -->        <td align="center" width=80px>&gt;&gt;=</td>        <td align="left">右移后赋值运算符</td>        <td align="left">变量 &gt;&gt;= 表达式</td>        <td align="center">——</td>    </tr>    <tr><!-- 9 -->        <td align="center" width=80px>&=</td>        <td align="left">按位与后赋值运算符</td>        <td align="left">变量 &= 表达式</td>        <td align="center">——</td>    </tr>    <tr><!-- 10 -->        <td align="center" width=80px>^=</td>        <td align="left">按位异或后赋值运算符</td>        <td align="left">变量 ^= 表达式</td>        <td align="center">——</td>    </tr>    <tr><!-- 11 -->        <td align="center" width=80px>|=</td>        <td align="left">按位或后赋值运算符</td>        <td align="left">变量 |= 表达式</td>        <td align="center">——</td>    </tr>    <tr>        <td align="center" width=80px>15</td>        <td align="center" width=80px>  , </td>        <td align="left">逗号运算符</td>        <td align="left">表达式1, 表达式2, …, 表达式n</td>        <td align="center">左&rarr;右</td>        <td align="center">——</td>    </tr></table>【注意】：<ul><li>优先级数字越小，优先级越高。</li><li>同一优先级的运算符，运算次序由结合方向决定</li><li>通常情况下取模运算( mod )和求余( rem )运算的目标结果相同，在大多数的编程语言里，都用 % 符号表示取模或者求余运算。不过还是要十分注意当前环境下 % 运算符的具体意义，因为在有负数存在的情况下，两者的结果可能是不一样的。</li></ul>
              </div>
            </details>

<h1 id="四、位逻辑运算"><a href="#四、位逻辑运算" class="headerlink" title="四、位逻辑运算"></a><font size=3>四、位逻辑运算</font></h1><h2 id="1-与运算"><a href="#1-与运算" class="headerlink" title="1. 与运算"></a><font size=3>1. 与运算</font></h2><table>
    <tr><td align="center">A</td><td align="center">B</td><td align="center">A & B</td></tr>
    <tr><td align="center">1</td><td align="center">1</td><td align="center">1</td></tr>
    <tr><td align="center">1</td><td align="center">0</td><td align="center">0</td></tr>
    <tr><td align="center">0</td><td align="center">1</td><td align="center">0</td></tr>
    <tr><td align="center">0</td><td align="center">0</td><td align="center">0</td></tr>
</table>


<h2 id="2-或运算"><a href="#2-或运算" class="headerlink" title="2. 或运算"></a><font size=3>2. 或运算</font></h2><table>
    <tr><td align="center">A</td><td align="center">B</td><td align="center">A | B</td></tr>
    <tr><td align="center">1</td><td align="center">1</td><td align="center">1</td></tr>
    <tr><td align="center">1</td><td align="center">0</td><td align="center">1</td></tr>
    <tr><td align="center">0</td><td align="center">1</td><td align="center">1</td></tr>
    <tr><td align="center">0</td><td align="center">0</td><td align="center">0</td></tr>
</table>


<h2 id="3-非运算"><a href="#3-非运算" class="headerlink" title="3. 非运算"></a><font size=3>3. 非运算</font></h2><table>
    <tr><td align="center">A</td><td align="center">!A</td></tr>
    <tr><td align="center">1</td><td align="center">0</td></tr>
    <tr><td align="center">0</td><td align="center">1</td></tr>
</table>


<h2 id="4-异或运算"><a href="#4-异或运算" class="headerlink" title="4. 异或运算"></a><font size=3>4. 异或运算</font></h2><table>
    <tr><td align="center">A</td><td align="center">B</td><td align="center">A ^ B</td></tr>
    <tr><td align="center">1</td><td align="center">1</td><td align="center">0</td></tr>
    <tr><td align="center">1</td><td align="center">0</td><td align="center">1</td></tr>
    <tr><td align="center">0</td><td align="center">1</td><td align="center">1</td></tr>
    <tr><td align="center">0</td><td align="center">0</td><td align="center">0</td></tr>
</table>
【**相同为0，不同为1**】

<h2 id="5-同或运算"><a href="#5-同或运算" class="headerlink" title="5. 同或运算"></a><font size=3>5. 同或运算</font></h2><table>
    <tr><td align="center">A</td><td align="center">B</td><td align="center">!(A ^ B)</td></tr>
    <tr><td align="center">1</td><td align="center">1</td><td align="center">1</td></tr>
    <tr><td align="center">1</td><td align="center">0</td><td align="center">0</td></tr>
    <tr><td align="center">0</td><td align="center">1</td><td align="center">0</td></tr>
    <tr><td align="center">0</td><td align="center">0</td><td align="center">1</td></tr>
</table>
【**相同为1，不同为0**】

<h2 id="6-逻辑运算应用"><a href="#6-逻辑运算应用" class="headerlink" title="6. 逻辑运算应用"></a><font size=3>6. 逻辑运算应用</font></h2><h3 id="6-1-位清-0"><a href="#6-1-位清-0" class="headerlink" title="6.1 位清 0 "></a><font size=3>6.1 位清 0 </font></h3><p>有的时候我们需要将一个数据的某一位清 0 而又不希望影响其他位的数据，我们可以这样来写：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">a = a &amp; (~(<span class="number">1</span> &lt;&lt; n));  <span class="comment">/* 将 a 的第 n 位清 0 ，其他位保持不变，n 从 0 开始计算 */</span></span><br></pre></td></tr></table></figure>

<p><strong>【语句分析】</strong>假设 a 为 32 位数据， n 为第 3 位，目的是将第 3 位清 0 ，而不影响其他位：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">n               : <span class="number">3</span></span><br><span class="line">(<span class="number">1</span> &lt;&lt; n)        : <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00001000</span></span><br><span class="line">    </span><br><span class="line">(~(<span class="number">1</span> &lt;&lt; n))     : <span class="number">11111111</span> <span class="number">11111111</span> <span class="number">11111111</span> <span class="number">11110111</span></span><br><span class="line">a               : <span class="number">11111111</span> <span class="number">11111111</span> <span class="number">11111111</span> <span class="number">11111111</span></span><br><span class="line">    </span><br><span class="line">a &amp; (~(<span class="number">1</span> &lt;&lt; n)) : <span class="number">11111111</span> <span class="number">11111111</span> <span class="number">11111111</span> <span class="number">11110111</span></span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV01-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/LV01-02-C%E8%AF%AD%E8%A8%80-%E5%8F%98%E9%87%8F%E4%B8%8E%E8%BF%90%E7%AE%97%E7%AC%A6/img/image-20220731101731680.png" alt="image-20220731101731680" style="zoom:50%;" />

<h3 id="6-2-位置-1"><a href="#6-2-位置-1" class="headerlink" title="6.2 位置 1 "></a><font size=3>6.2 位置 1 </font></h3><p>有的时候我们需要将一个数据的某一位置 1 而又不希望影响其他位的数据，我们可以这样来写：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">a = a | (<span class="number">1</span> &lt;&lt; n);  <span class="comment">/* 将 a 的第 n 位置 1 ，其他位保持不变， n 从 0 开始计算 */</span></span><br></pre></td></tr></table></figure>

<p><strong>【语句分析】</strong>假设 a 为 32 位数据， n 为第 3 位，目的是将第 3 位置 1 ，而不影响其他位：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">n            : <span class="number">3</span> </span><br><span class="line">(<span class="number">1</span> &lt;&lt; n)     : <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00001000</span></span><br><span class="line"></span><br><span class="line">a            : <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00000000</span></span><br><span class="line">    </span><br><span class="line">a | (<span class="number">1</span> &lt;&lt; n) : <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00001000</span></span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV01-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/LV01-02-C%E8%AF%AD%E8%A8%80-%E5%8F%98%E9%87%8F%E4%B8%8E%E8%BF%90%E7%AE%97%E7%AC%A6/img/image-20220731101932124.png" alt="image-20220731101932124" style="zoom:50%;" />

<h3 id="6-3-应用实例"><a href="#6-3-应用实例" class="headerlink" title="6.3 应用实例"></a><font size=3>6.3 应用实例</font></h3><blockquote>
<p>【问题】unsigned int a;  将a的第[7:4]位置为0101，其他位保持不变。</p>
</blockquote>
<p><strong>【分析过程】</strong></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">******** ******** ******** ********</span><br><span class="line">******** ******** ******** <span class="number">0101</span>****</span><br><span class="line"><span class="type">unsigned</span> <span class="type">int</span> a    : <span class="number">11111111</span> <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">10101111</span></span><br><span class="line"><span class="comment">/* 1.先清零 */</span></span><br><span class="line"><span class="number">0xF</span>               : <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00001111</span></span><br><span class="line">(<span class="number">0xF</span> &lt;&lt; <span class="number">4</span>)        : <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">11110000</span></span><br><span class="line">~(<span class="number">0xF</span> &lt;&lt; <span class="number">4</span>)       : <span class="number">11111111</span> <span class="number">11111111</span> <span class="number">11111111</span> <span class="number">00001111</span></span><br><span class="line">a                 : <span class="number">11111111</span> <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">10101111</span></span><br><span class="line">a &amp; (~(<span class="number">0xF</span> &lt;&lt; <span class="number">4</span>)) : <span class="number">11111111</span> <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00001111</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/* 2.再置位 */</span></span><br><span class="line"><span class="number">0x5</span>               : <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00000101</span></span><br><span class="line">(<span class="number">0x5</span> &lt;&lt; <span class="number">4</span>)        : <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">01010000</span></span><br><span class="line">a                 : <span class="number">11111111</span> <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00001111</span></span><br><span class="line">a | (<span class="number">0x5</span> &lt;&lt; <span class="number">4</span>)    : <span class="number">11111111</span> <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">01011111</span></span><br><span class="line"></span><br><span class="line">=&gt; a = a &amp; (~(<span class="number">0xF</span> &lt;&lt; <span class="number">4</span>)) | (<span class="number">0x5</span> &lt;&lt; <span class="number">4</span>);</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV01-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/LV01-02-C%E8%AF%AD%E8%A8%80-%E5%8F%98%E9%87%8F%E4%B8%8E%E8%BF%90%E7%AE%97%E7%AC%A6/img/image-20220731103108642-16827691783556.png" alt="image-20220731103108642" style="zoom: 33%;" />


    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/ce2c2639.html">LV01-02-C语言-变量与运算符</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2022年01月11日 - 16:29</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/ce2c2639.html" title="LV01-02-C语言-变量与运算符">https://sumumm.github.io/post/ce2c2639.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/LV01-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/" rel="tag"><i class="fa fa-tag"></i> LV01-C语言基础</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/b9a7171d.html" rel="prev" title="LV01-03-C语言-输入与输出">
                  <i class="fa fa-angle-left"></i> LV01-03-C语言-输入与输出
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/e8ba6a9c.html" rel="next" title="LV01-01-C语言-数据类型">
                  LV01-01-C语言-数据类型 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">false</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
